
package com.joysuch.wwyt.common.enums;

import com.joysuch.wwyt.edu.entity.EduCourseware;
import com.joysuch.wwyt.edu.entity.EduExam;
import com.joysuch.wwyt.edu.entity.EduQuestion;
import com.joysuch.wwyt.edu.entity.EduTestPaper;
import com.joysuch.wwyt.edu.entity.EduTrainningPlan;
import com.joysuch.wwyt.edu.entity.EduTrainningRecord;

public enum CommonTypes {

    // COURSE("cou", "课程", EduCourse.class, "typeId"),
    COURSEWARE("cw", "课件", EduCourseware.class, "typeId"),
    QUESTION("ques", "试题", EduQuestion.class, "questionTypeId"),
    TEST_PAPER("paper", "试卷", EduTestPaper.class, "typeId"),
    TRAINNING_PLAN("tplan", "培训计划", EduTrainningPlan.class, "typeId"),
    TRAINNING_RECORD("treco", "培训记录", EduTrainningRecord.class, "trainningTypeId"),
    EXAM("exam", "考试", EduExam.class, "typeId");

    private String code;
    private String name;
    private Class entityClass;
    private String typeFieldName;

    private CommonTypes(String code, String name, Class entityClass, String typeFieldName) {
        this.code = code;
        this.name = name;
        this.entityClass = entityClass;
        this.typeFieldName = typeFieldName;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public Class getEntityClass() {
        return entityClass;
    }

    public String getTypeFieldName() {
        return typeFieldName;
    }

    public static CommonTypes findByName(String name) {
        CommonTypes[] values = CommonTypes.values();
        for (CommonTypes v : values) {
            if (v.getName().equals(name)) {
                return v;
            }
        }
        return null;
    }

    public static CommonTypes findByCode(String code) {
        CommonTypes[] values = CommonTypes.values();
        for (CommonTypes v : values) {
            if (v.getCode().equals(code)) {
                return v;
            }
        }
        return null;
    }

    public static String findNameByCode(String code) {
        CommonTypes types = findByCode(code);
        return types == null ? null : types.name;
    }
}
